package com.dysoft.flesh.gl;

import com.dysoft.flesh.RenderContext;
import com.dysoft.flesh.Renderer;

import javax.media.opengl.GL;
import java.nio.FloatBuffer;

/**
 * @author Sean Micklethwaite
 *         Aug 16, 2010 8:28:36 PM
 */
public class GLVertexBufferMesh extends GLVertexBuffer implements Renderer {
	final int vertexCount;

	public GLVertexBufferMesh(FloatBuffer vertices, int vertexCount) {
		super(vertices, Type.VERTICES);
		this.vertexCount = vertexCount;
	}

	public GLVertexBufferMesh(float [] vertices, int vertexCount) {
		this(FloatBuffer.wrap(vertices), vertexCount);
	}

	public void render(RenderContext ctx) {
		activate(ctx);
		((GLRenderer.GLRenderContext)ctx).getGL().glDrawArrays(GL.GL_TRIANGLES, 0, vertexCount);
		deactivate(ctx);
	}
}
